﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MaymuseMS.Models;
using MaymuseMS.Models.ValueObject;

namespace MaymuseMS.DAL {
    public class FinishedDepositoryRepository : GenericRepository<FinishedDepository> {
        public FinishedDepositoryRepository(MaymuseMSContext context)
            : base(context) {

        }

        //public void Increase(ProductValueObject productValueObject, int count, string location) {
        //    var finishedDepository = Get(productValueObject.Number);
        //    if (finishedDepository == null) {
        //        finishedDepository = new FinishedDepository {
        //            ProductValueObject = productValueObject, Total = 0, Location = ""
        //        };
        //        this.Add(finishedDepository);
        //    }

        //    finishedDepository.Total += count;

        //    if (!string.IsNullOrWhiteSpace(location) &&
        //        !finishedDepository.Location.Contains(location)) {
        //        if (!string.IsNullOrWhiteSpace(finishedDepository.Location)) {
        //            finishedDepository.Location += (", " + location);
        //        } else {
        //            finishedDepository.Location += (location);
        //        }
        //    }
        //}

        //public void Reduce(string number, int count) {
        //    var finishedDepository = Get(number);
        //    if (finishedDepository != null) {
        //        finishedDepository.Total -= count;
        //    }
        //}

        public FinishedDepository Get(string number) {
            var finishedDepository = this.dbSet.Where(p => p.ProductValueObject.Number == number).FirstOrDefault();
            return finishedDepository;
        }
    }
}